let public = 'http://bbpc.info';
let isLogin = sessionStorage.getItem('isLogin');
$('.help').on('click', 'a', function() {
	if(isLogin) {
		return false;
	}
})
if(isLogin) {
	$('.isLogin').text('注销')
	$('.jidianyun').find('a').attr({
		href: 'jidianyun.html'
	});
	$('.kuangchi').find('a').attr({
		href: 'minePool.html'
	});
	$('.invitation').find('a').attr({
		href: 'inviter.html'
	});
	$('.messages').find('a').attr({
		href: 'message.html'
	});
	$('.id-card').find('a').attr({
		href: 'identify.html'
	});
	$('.login-password').find('a').attr({
		href: 'modifyPassword.html'
	});
	$('.login-password.login').find('a').attr({
		href: 'tradePassword.html'
	});
	$('.help').find('a').attr({
		href: 'javasrcipt;;'
	});

	//获取用户信息
	$.ajax({
		url: public + '/UserCenter/getUserInfo',
		type: 'POST',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		success: function(res) {
			console.log(res);
			if(res.code === 200) {
				$('.info-top.noLogin').hide();
				$('.info-top.Login').show();
				// $('.info-top.Login').find('img').attr({src:''});
				$('.info-top.Login').find('p').html(`<span>${res.data.nickName}</span><span>${res.data.id}</span>`);
				// $('.info-top.Login').find('a').attr({href:''});
				sessionStorage.setItem('userId', res.data.id);
				sessionStorage.setItem('inviteCode', res.data.code);
			}
			if(res.code === 202) {
				alert('登录失效请重新登录');
				sessionStorage.removeItem('isLogin');
				window.location.href = 'home.html';
			}
		}
	})

} else {
	$('.isLogin').text('登录')
}
//注销
$('.isLogin').on('click', function() {
	if(isLogin){
		$.ajax({
		url: public + '/User/logout',
		type: 'POST',
		xhrFields: {
			withCredentials: true
		},
		crossDomain: true,
		dataType: 'json',
		success: function(res) {
			if(res.code === 200) {
				sessionStorage.removeItem('isLogin');
				window.location.href = 'home.html';
			}
			if(res.code === 211) {

			}
		}
	})
	}else{
		window.location.href = 'login.html';
	}
	
});

/*--------------------------------------------我是漂亮的分割线--------------------------------*/

/*--------------------------------------------我是漂亮的分割线--------------------------------*/